//
// ********************************************************************
// * License and Disclaimer                                           *
// *                                                                  *
// * The  Geant4 software  is  copyright of the Copyright Holders  of *
// * the Geant4 Collaboration.  It is provided  under  the terms  and *
// * conditions of the Geant4 Software License,  included in the file *
// * LICENSE and available at  http://cern.ch/geant4/license .  These *
// * include a list of copyright holders.                             *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.  Please see the license in the file  LICENSE  and URL above *
// * for the full disclaimer and the limitation of liability.         *
// *                                                                  *
// * This  code  implementation is the result of  the  scientific and *
// * technical work of the GEANT4 collaboration.                      *
// * By using,  copying,  modifying or  distributing the software (or *
// * any work based  on the software)  you  agree  to acknowledge its *
// * use  in  resulting  scientific  publications,  and indicate your *
// * acceptance of all terms of the Geant4 Software license.          *
// ********************************************************************
//
//
/// \file optical/wls/include/WLSEventAction.hh
/// \brief Definition of the WLSEventAction class
//

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

#ifndef WLSEventAction_h
#define WLSEventAction_h 1

#include "G4Types.hh"
#include "G4UserEventAction.hh"
#include <vector>

#include "G4UserRunAction.hh"
class WLSRun;
class G4Run;

// class WLSRunAction;

class WLSEventActionMessenger;

class WLSEventAction : public G4UserEventAction
{
public:
  WLSEventAction();
  ~WLSEventAction() override;

  void BeginOfEventAction(const G4Event *) override;
  void EndOfEventAction(const G4Event *) override;

  G4int GetEventNo();
  void SetEventVerbose(G4int);

  void AddTIR() { fNTIR += 1; };
  void AddExiting() { fNExiting += 1; };
  void AddEscapedEnd() { fEscapedEnd += 1; };
  void AddEscapedMid() { fEscapedMid += 1; };
  void AddBounce() { fBounce += 1; };
  void AddWLSBounce() { fWLSBounce += 1; };
  void AddClad1Bounce() { fClad1Bounce += 1; };
  void AddClad2Bounce() { fClad2Bounce += 1; };
  void AddReflected() { fReflected += 1; };
  void AddEscaped() { fEscaped += 1; };
  void AddMirror() { fMirror += 1; };
  ///////////////////////////////////////////////////////////
  void AddMuonEdep(G4double edep) { fMuonEdep += edep; }; // 统计缪子沉积能量
  void Addpphoton() { fPNPhoton += 1; }                   // 统计初始光子数
  std::vector<G4double> &GetEnergy() { return fVecEnergy; };
  std::vector<G4double> &GetTime() { return fVecTime; };
  std::vector<G4int> &GetDetectorIndex() { return fVecDetectorIndex; };
  std::vector<G4int> &GetNPhoton() { return fVecNPhoton; };
  std::vector<G4double> &GetMuonEdep() { return fVecMuonEdep; };
  std::vector<G4int> &GetNPPhoton() { return fVecNPPhoton; };
  std::vector<G4double> &GetFiberZ() { return fVecFiberZ; };

  void AddFiberZ(G4double z) { fFiberZ = z; };

  void AddCoreTIR() { fCoreTIR += 1; };
  void AddCoreR() { fCoreR += 1; };
  void AddClad1TIR() { fClad1TIR += 1; };
  void AddClad1R() { fClad1R += 1; };
  void AddCoupleR() { fCoupleR += 1; };

  void AddAbsCoreL(G4double l) { fAbsCoreL += l; };
  void AddAbsClad1L(G4double l) { fAbsClad1L += l; };

  G4double GetInitGamma() { return fInitGamma; };
  void SetInitGamma() { fInitGamma = 0; };
  G4double GetInitCoupleR() { return fInitCoupleR; };
  void SetInitCoupleR() { fInitCoupleR = 0; };

private:
  WLSEventActionMessenger *fEventMessenger = nullptr;
  // WLSRunAction *fRunAction = nullptr;

  G4int fVerboseLevel = 0;

  G4int fMPPCCollID = 0;

  G4int fNTIR = 0;
  G4int fNExiting = 0;
  G4int fEscapedEnd = 0;
  G4int fEscapedMid = 0;
  G4int fBounce = 0;
  G4int fWLSBounce = 0;
  G4int fClad1Bounce = 0;
  G4int fClad2Bounce = 0;
  G4int fReflected = 0;
  G4int fEscaped = 0;
  G4int fMirror = 0;
  //////////////////////////////////////////////////////////
  G4double fMuonEdep = 0.;
  G4int fPNPhoton = 0;
  G4double fFiberZ = 0.;
  std::vector<G4double> fVecEnergy;
  std::vector<G4double> fVecTime;
  std::vector<G4int> fVecDetectorIndex;
  std::vector<G4int> fVecNPhoton;
  std::vector<G4double> fVecMuonEdep;
  std::vector<G4int> fVecNPPhoton;
  std::vector<G4double> fVecFiberZ;

  G4double fCoreTIR = 0.;
  G4double fCoreR = 0.;
  G4double fClad1TIR = 0.;
  G4double fClad1R = 0.;
  G4double fCoupleR = 0.;
  G4double fAbsCoreL = 0.;
  G4double fAbsClad1L = 0.;

  G4double fInitGamma = -1.;
  G4double fInitCoupleR = -1.;
};

#endif
